/*
 *
 * http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/setup.html
 * http://netbeans.org/kb/docs/java/javase-jws.html
 * 
 */
package newcrunch.gui;

import java.awt.CardLayout;
import newcrunch.grader.AuthManager;
import newcrunch.security.CustomSecurityManager;
import newcrunch.util.PropertyLoader;

/**
 * @author WL
 */
public class NewCrunch extends javax.swing.JFrame {
    private AuthManager authManager;
    
    public AuthManager getAuthManager()
    {
        return authManager;
    }
        
    private void myInit()
    {                   
        RightTab firstTab = rightPanel.getTab(0);
        firstTab.configureEditorListener(classList);
        
        authManager = new AuthManager();
        authManager.setGradingPanel(gradingPanel);
        authManager.setLoginPanel(loginPanel);
        authManager.setRightPanel(rightPanel);
        authManager.setSelectionPanel(selectionPanel);
    }
    
    /**
     * Method called after the constructor has been created
     */
    private void postInit()
    {
        //update title from property file
        String newTitle = PropertyLoader.getStringProperty("gui.title");
        
        if (newTitle != null)
            this.setTitle(newTitle);
        
        //connects the grading panel to right panel
        gradingPanel.setRightPanel(rightPanel);
        
        rightPanel.linkClassList(classList);
    }
    
    /**
     * Creates new form NewCrunchGU
     */
    public NewCrunch() {
        initComponents();
        myInit();
    }
    
    public void reset()
    {
        authManager.reset();
        rightPanel.reset();
        classList.regenerateTree("");
        ((CardLayout)jPanel9.getLayout()).show(jPanel9, "loginDisplay");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel10 = new javax.swing.JPanel();
        jSplitPane5 = new javax.swing.JSplitPane();
        jSplitPane4 = new javax.swing.JSplitPane();
        jPanel9 = new javax.swing.JPanel();
        loginPanel = new newcrunch.grader.LoginPanel();
        gradingPanel = new newcrunch.grader.GradingPanel();
        selectionPanel = new newcrunch.grader.SelectionPanel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        classList = new newcrunch.gui.tree.CustomTree();
        jPanel1 = new javax.swing.JPanel();
        rightPanel = new newcrunch.gui.RightPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CodeCrunch Grader Application");

        jSplitPane5.setDividerLocation(180);

        jSplitPane4.setDividerLocation(250);
        jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jPanel9.setLayout(new java.awt.CardLayout());
        jPanel9.add(loginPanel, "loginDisplay");
        jPanel9.add(gradingPanel, "gradingDisplay");
        jPanel9.add(selectionPanel, "selectionDisplay");

        jSplitPane4.setTopComponent(jPanel9);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        classList.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(classList);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
        );

        jSplitPane4.setRightComponent(jPanel6);

        jSplitPane5.setLeftComponent(jSplitPane4);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)
        );

        jSplitPane5.setRightComponent(jPanel1);

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 924, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 694, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        System.setSecurityManager(new CustomSecurityManager());
        
        /*
        * Create and display the form
        */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                NewCrunch gui = new NewCrunch();
                gui.postInit();
                gui.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private newcrunch.gui.tree.CustomTree classList;
    private newcrunch.grader.GradingPanel gradingPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane4;
    private javax.swing.JSplitPane jSplitPane5;
    private newcrunch.grader.LoginPanel loginPanel;
    private newcrunch.gui.RightPanel rightPanel;
    private newcrunch.grader.SelectionPanel selectionPanel;
    // End of variables declaration//GEN-END:variables
}